home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetDate.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.4 KB  |  103 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import symjava.sql.Date;
  7. import symjava.sql.SQLException;
  8. import symjava.sql.Timestamp;
  9.  
  10. class NetDate extends DateTimeField {
  11.    Date _dateVal;
  12.  
  13.    int getType() {
  14.       return 75;
  15.    }
  16.  
  17.    void readData(DataInputStream is) throws SQLException, IOException, ErrorException {
  18.       int iYear = 0;
  19.       ServerObject obj = (ServerObject)NetClass.getNextObject(is);
  20.       if (obj.getType() == 51) {
  21.          iYear = ((NetData)obj).getInt();
  22.       } else {
  23.          ((ServerObject)this).onObjectError(obj);
  24.       }
  25.  
  26.       int iMonth = 0;
  27.       obj = (ServerObject)NetClass.getNextObject(is);
  28.       if (obj.getType() == 51) {
  29.          iMonth = ((NetData)obj).getInt();
  30.       } else {
  31.          ((ServerObject)this).onObjectError(obj);
  32.       }
  33.  
  34.       int iDay = 0;
  35.       obj = (ServerObject)NetClass.getNextObject(is);
  36.       if (obj.getType() == 51) {
  37.          iDay = ((NetData)obj).getInt();
  38.       } else {
  39.          ((ServerObject)this).onObjectError(obj);
  40.       }
  41.  
  42.       if (!super._null) {
  43.          try {
  44.             this._dateVal = new Date(iYear, iMonth - 1, iDay);
  45.          } catch (IllegalArgumentException var6) {
  46.             this._dateVal = null;
  47.          }
  48.       } else {
  49.          this._dateVal = null;
  50.       }
  51.    }
  52.  
  53.    void writeData(DataOutputStream os) throws IOException {
  54.       NetData data = new NetData((short)this._dateVal.getYear());
  55.       data.write(os);
  56.       data = new NetData((short)(this._dateVal.getMonth() + 1));
  57.       data.write(os);
  58.       data = new NetData((short)this._dateVal.getDate());
  59.       data.write(os);
  60.    }
  61.  
  62.    public String getString() throws SQLException {
  63.       return ((Field)this).isNull() ? null : this._dateVal.toString();
  64.    }
  65.  
  66.    public Date getDate() throws SQLException {
  67.       return ((Field)this).isNull() ? null : this._dateVal;
  68.    }
  69.  
  70.    public Timestamp getTimestamp() throws SQLException {
  71.       return ((Field)this).isNull() ? null : new Timestamp(this._dateVal.getYear(), this._dateVal.getMonth(), this._dateVal.getDate(), 0, 0, 0, 0);
  72.    }
  73.  
  74.    public void setString(String x) throws SQLException {
  75.       this._dateVal = Date.valueOf(x);
  76.       super._null = false;
  77.    }
  78.  
  79.    public void setDate(Date x) throws SQLException {
  80.       this._dateVal = x;
  81.       super._null = false;
  82.    }
  83.  
  84.    public void setTimestamp(Timestamp x) throws SQLException {
  85.       this._dateVal.setYear(((java.util.Date)x).getYear());
  86.       this._dateVal.setMonth(((java.util.Date)x).getMonth());
  87.       this._dateVal.setDate(((java.util.Date)x).getDate());
  88.       super._null = false;
  89.    }
  90.  
  91.    public int getSQLType() {
  92.       return 91;
  93.    }
  94.  
  95.    public Object getObject() throws SQLException {
  96.       return this.getDate();
  97.    }
  98.  
  99.    public void setObject(Object obj) throws SQLException {
  100.       this.setDate((Date)obj);
  101.    }
  102. }
  103.